package com.cl.dto;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ComboTreeDTO {
	public String text;
	public String cls;
	public boolean expanded;
	public boolean checked;
	public boolean leaf;
	public List<ComboTreeDTO> children;
	
	public ComboTreeDTO(){
		this.expanded = false;
		this.checked = false;
		this.leaf = true;
		this.children = new ArrayList<ComboTreeDTO>();
	}
	
	public ComboTreeDTO(String text){
		this.text = text;
		this.expanded = false;
		this.checked = false;
		this.leaf = true;
		this.children = new ArrayList<ComboTreeDTO>();	
	}
	
	public boolean addChild(ComboTreeDTO child){
		return children.add(child);
	}
	
	public ComboTreeDTO findNodeByText(String text){
		if(this.text.equalsIgnoreCase(text))
			return this;
		if(this.children==null||this.children.isEmpty())
			return null;
		for(int i=0; i<children.size(); i++){
			ComboTreeDTO child = children.get(i);
			ComboTreeDTO node = child.findNodeByText(text);
			if(node!=null)
				return node;
		}
		return null;
	}
	
	public static ComboTreeDTO findInListByText(List<ComboTreeDTO> list,String text){
		if(list==null || list.isEmpty())
			return null;
		for(int i=0;i<list.size();i++){
			if(list.get(i).text.equals(text))
				return list.get(i);
		}
		return null;
	}
}
